home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import Common.*;
- import flash.display.*;
- import flash.events.Event;
- import flash.events.FullScreenEvent;
- import flash.media.SoundTransform;
- import flash.net.*;
- import flash.utils.*;
-
- public class Storage
- {
-
- internal static const OPTIONSKEY:String = "GameServicesGroup/CluelessDemo/0.4/Options";
-
- internal static var _storage:Storage = null;
-
- internal static const PROFILEKEY:String = "GameServicesGroup/CluelessDemo/0.4/Profiles";
-
- internal static const HIGHSCOREKEY:String = "GameServicesGroup/CluelessDemo/0.4/Highscore";
-
-
- public var _scores:Array;
-
- public var Pause:Boolean = false;
-
- internal var _soOptions:SharedObject;
-
- internal var _sCurrentBGM:String = "MenuMusic";
-
- internal var _soHScores:SharedObject;
-
- internal var _stage:Stage;
-
- public function Storage()
- {
- _sCurrentBGM = "MenuMusic";
- Pause = false;
- super();
- _soOptions = SharedObject.getLocal(OPTIONSKEY,"/");
- _soHScores = SharedObject.getLocal(HIGHSCOREKEY,"/");
- initHighScore();
- }
-
- public static function getInstance() : Storage
- {
- if(_storage == null)
- {
- _storage = new Storage();
- }
- return _storage;
- }
-
- public static function clone(param1:Array) : Array
- {
- var _loc2_:Array = null;
- var _loc3_:int = 0;
- _loc2_ = new Array();
- _loc3_ = 0;
- while(_loc3_ < param1.length)
- {
- if(param1[_loc3_] is Array)
- {
- _loc2_.push(clone(param1[_loc3_]));
- }
- else
- {
- _loc2_.push(param1[_loc3_]);
- }
- _loc3_++;
- }
- return _loc2_;
- }
-
- public function get ParticleEffects() : Boolean
- {
- var _loc1_:Boolean = false;
- _loc1_ = true;
- if(_soOptions.data.ParticleEffects != null)
- {
- _loc1_ = Boolean(_soOptions.data.ParticleEffects);
- }
- return _loc1_;
- }
-
- public function set BGMVolume(param1:Number) : void
- {
- _soOptions.data.BGMVolume = param1;
- trace("Set volume " + param1.toString());
- _soOptions.flush();
- applyBGMState();
- }
-
- public function applyFullscreenState() : void
- {
- }
-
- public function set BGMEnabled(param1:Boolean) : void
- {
- _soOptions.data.BGMEnabled = param1;
- _soOptions.flush();
- applyBGMState();
- }
-
- public function set FullscreenEnabled(param1:Boolean) : void
- {
- _soOptions.data.FullscreenEnabled = param1;
- _soOptions.flush();
- applyFullscreenState();
- }
-
- public function resetScores() : void
- {
- var _loc1_:* = undefined;
- for(_loc1_ in _soHScores.data)
- {
- delete _soHScores.data[_loc1_];
- }
- _soHScores.flush();
- }
-
- public function set VoiceOvers(param1:Boolean) : void
- {
- _soOptions.data.VoiceOvers = param1;
- _soOptions.flush();
- }
-
- internal function onFullScreen(param1:FullScreenEvent) : void
- {
- _soOptions.data.FullscreenEnabled = param1.fullScreen;
- _soOptions.flush();
- }
-
- public function saveProfiles() : *
- {
- var _loc1_:SharedObject = null;
- var _loc2_:Array = null;
- var _loc3_:Profile = null;
- _loc1_ = SharedObject.getLocal(PROFILEKEY,"/");
- _loc2_ = new Array();
- for each(_loc3_ in Profile.ProfileList)
- {
- _loc2_.push(_loc3_.save());
- }
- _loc2_.push(Profile.ProfileList.length);
- _loc2_.push(Profile.CurrentProfile.Name);
- _loc1_.data.profiles = _loc2_;
- _loc1_.flush();
- _loc1_.close();
- _loc1_ = null;
- }
-
- public function initHighScore() : void
- {
- var _loc1_:* = undefined;
- _scores = new Array();
- if(_soHScores.size != 0)
- {
- for(_loc1_ in _soHScores.data)
- {
- _scores.push(_soHScores.data[_loc1_]);
- }
- _scores.sortOn("Score",Array.DESCENDING);
- }
- }
-
- public function applySFXState() : void
- {
- MainDocument.DefaultSoundTransform = new SoundTransform(SFXVolume,0);
- SoundManager.getInstance().SFXVolume = SFXVolume;
- if(Pause)
- {
- }
- MainDocument.DefaultSoundTransform = new SoundTransform(0,0);
- }
-
- public function get BGMVolume() : Number
- {
- var _loc1_:Number = NaN;
- _loc1_ = 1;
- if(_soOptions.data.BGMVolume != null)
- {
- _loc1_ = Number(_soOptions.data.BGMVolume);
- trace("Get volume create " + _loc1_.toString());
- }
- trace("Get volume " + _loc1_.toString());
- return _loc1_;
- }
-
- public function get SFXVolume() : Number
- {
- var _loc1_:Number = NaN;
- _loc1_ = 1;
- if(_soOptions.data.SFXVolume != null)
- {
- _loc1_ = Number(_soOptions.data.SFXVolume);
- trace("Get volume create " + _loc1_.toString());
- }
- trace("Get volume " + _loc1_.toString());
- return _loc1_;
- }
-
- public function newProfile(param1:String) : void
- {
- var _loc2_:Profile = null;
- _loc2_ = new Profile();
- _loc2_.Name = param1;
- Profile.CurrentProfile = _loc2_;
- Profile.ProfileList.push(_loc2_);
- saveProfiles();
- }
-
- public function set SFXVolume(param1:Number) : void
- {
- _soOptions.data.SFXVolume = param1;
- trace("Set volume " + param1.toString());
- _soOptions.flush();
- applySFXState();
- }
-
- public function createStartingProfile() : void
- {
- var _loc1_:Profile = null;
- _loc1_ = new Profile();
- _loc1_.Name = "Cher";
- Profile.CurrentProfile = _loc1_;
- Profile.ProfileList = new Array();
- Profile.ProfileList.push(_loc1_);
- }
-
- public function storeHighScore() : void
- {
- var _loc1_:* = undefined;
- var _loc2_:String = null;
- var _loc3_:int = 0;
- _loc3_ = 1;
- if(_scores.length > 0)
- {
- for each(_loc1_ in _scores)
- {
- _loc2_ = "HScore" + _loc3_;
- _soHScores.data[_loc2_] = _loc1_;
- _loc3_++;
- if(_loc3_ > 12)
- {
- break;
- }
- }
- _soHScores.flush();
- }
- }
-
- public function loadProfiles() : *
- {
- var _loc1_:SharedObject = null;
- var _loc2_:Array = null;
- var _loc3_:String = null;
- var _loc4_:int = 0;
- var _loc5_:Profile = null;
- _loc1_ = SharedObject.getLocal(PROFILEKEY,"/");
- if(typeof _loc1_.data.profiles == "undefined")
- {
- _loc1_.close();
- _loc1_ = null;
- Profile.ProfileList = new Array();
- return;
- }
- _loc2_ = Storage.clone(_loc1_.data.profiles);
- _loc3_ = _loc2_.pop() as String;
- _loc4_ = _loc2_.pop() as int;
- Profile.ProfileList = new Array();
- while(_loc4_ > 0)
- {
- _loc4_--;
- (_loc5_ = new Profile()).load(_loc2_.pop() as Array);
- Profile.ProfileList.push(_loc5_);
- }
- Profile.ProfileList.reverse();
- Profile.CurrentProfile = Profile.getProfile(_loc3_);
- _loc1_.close();
- _loc1_ = null;
- }
-
- public function get VoiceOvers() : Boolean
- {
- var _loc1_:Boolean = false;
- _loc1_ = true;
- if(_soOptions.data.VoiceOvers != null)
- {
- _loc1_ = Boolean(_soOptions.data.VoiceOvers);
- }
- return _loc1_;
- }
-
- public function onActivate(param1:Event) : void
- {
- applyBGMState();
- }
-
- public function onDeactivate(param1:Event) : void
- {
- SoundManager.getInstance().stopBG();
- }
-
- public function playBGM(param1:String) : void
- {
- var musicclass:Class = null;
- var sMusic:String = param1;
- _sCurrentBGM = sMusic;
- trace("Music set to: " + sMusic);
- if(BGMEnabled && _sCurrentBGM != "")
- {
- try
- {
- musicclass = getDefinitionByName(_sCurrentBGM) as Class;
- if(musicclass != null)
- {
- SoundManager.getInstance().playSoundFromRes(sMusic,new musicclass(),SoundObject.C_BG);
- SoundManager.getInstance().BGVolume = BGMVolume;
- }
- }
- catch(ex:*)
- {
- }
- }
- else
- {
- SoundManager.getInstance().stopBG();
- }
- if(Pause)
- {
- SoundManager.getInstance().stopBG();
- }
- }
-
- public function get FullscreenEnabled() : Boolean
- {
- var _loc1_:Boolean = false;
- _loc1_ = false;
- if(_soOptions.data.FullscreenEnabled != null)
- {
- _loc1_ = Boolean(_soOptions.data.FullscreenEnabled);
- }
- return _loc1_;
- }
-
- public function applyBGMState() : void
- {
- playBGM(_sCurrentBGM);
- }
-
- public function set ParticleEffects(param1:Boolean) : void
- {
- _soOptions.data.ParticleEffects = param1;
- _soOptions.flush();
- }
-
- public function get BGMEnabled() : Boolean
- {
- var _loc1_:Boolean = false;
- _loc1_ = true;
- if(_soOptions.data.BGMEnabled != null)
- {
- _loc1_ = Boolean(_soOptions.data.BGMEnabled);
- }
- return _loc1_;
- }
-
- public function setStage(param1:Stage) : void
- {
- _stage = param1;
- }
-
- public function deleteProfile(param1:String) : void
- {
- var _loc2_:Array = null;
- var _loc3_:Profile = null;
- _loc2_ = Profile.ProfileList;
- Profile.ProfileList = new Array();
- for each(_loc3_ in _loc2_)
- {
- if(_loc3_.Name != param1)
- {
- Profile.ProfileList.push(_loc3_);
- }
- }
- saveProfiles();
- }
- }
- }
-